package gui2;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
import entity.Manager;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import management.CheckForm;

/**
 *
 * @author Cucnth
 */
public class FrAdmin extends javax.swing.JFrame {

    // private Manager manager;
    Manager manager;
    GUIFeedBack fb = new GUIFeedBack();
    GUIMenu menu = new GUIMenu();
    GUIManagerBill mb;
    GUIMngManager mana = new GUIMngManager();
    GUIMgmCustomer maCus = new GUIMgmCustomer();
    GUILogin lg = new GUILogin();
    GUIAboutUs au;

    public Component getItem(String itemName) {
        for (Component component : jMenuBar1.getComponents()) {
            if (component instanceof JMenu) {
                JMenu mnu = (JMenu) component;

                for (int i = 0; i < mnu.getItemCount(); i++) {
                    JMenuItem mnuItem = mnu.getItem(i);

                    if (mnuItem instanceof JMenuItem) {
                        String name = mnuItem.getName();

                        if (name != null) {
                            if (name.equalsIgnoreCase(itemName)) {
                                return mnuItem;
                            }
                        }
                    }
                }
            }
        }

        return null;
    }

    public void setEnabledItem(Component com, boolean enabled) {
        if (com != null) {
            com.setEnabled(enabled);
        }
    }
    String username;

    public FrAdmin(Manager manager) {
        try {
            initComponents();
            this.manager = manager;
            this.setContentPane(desktop);
            this.setSize(0, 25);
            CheckForm.setOptionFrame(this, "Canteen Management System");
            CheckForm.openFrame(this, 1024, 650);
            this.setResizable(false);
            showInfo();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error: " + ex.getMessage(), "Notice", JOptionPane.OK_OPTION);
        }
    }

    public void showInfo() throws Exception {
        try {
            CheckForm.disposeIFrame(this);

            lblShowDes.setText("Canteen Management System");
            lblShowDes.setSize(1000, 70);
            lblShowDes.setForeground(Color.DARK_GRAY);
            lblShowDes.setFont(new Font("Arial", Font.ITALIC, 60));//Lucida Calligraphy | Lucida Handwriting | Old English Text MT            
            lblShowDes.setVisible(true);
            desktop.add(lblShowDes);

            lblGroup.setText(" Group 3 - C1109G - FPT - Aptech");
            lblGroup.setSize(1000, 40);
            lblGroup.setForeground(Color.DARK_GRAY);
            lblGroup.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 30));//Lucida Calligraphy | Lucida Handwriting | Old English Text MT
            lblGroup.setVisible(true);
            desktop.add(lblGroup);
            if (manager.getUserName() != null) {
                lblUserName.setText("Hello  " + manager.getUserName() + "!");
                lblUserName.setSize(1000, 25);
                lblUserName.setLocation(5, 5);
                lblUserName.setForeground(Color.red);
                lblUserName.setFont(new Font("", Font.PLAIN, 16));
                lblUserName.setVisible(true);
                desktop.add(lblUserName);
            }
            
             this.setEnabledItem(itemLogin, false);
            
        } catch (Exception ex) {
            throw ex;
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktop = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        mnuFile = new javax.swing.JMenu();
        itemLogin = new javax.swing.JMenuItem();
        itemLogout = new javax.swing.JMenuItem();
        itemExit = new javax.swing.JMenuItem();
        mnuMenu = new javax.swing.JMenu();
        itemMenuInfo = new javax.swing.JMenuItem();
        mnuBill = new javax.swing.JMenu();
        itemBill = new javax.swing.JMenuItem();
        mnuStaffManagement = new javax.swing.JMenu();
        itemManager = new javax.swing.JMenuItem();
        mnuAdminManagement = new javax.swing.JMenu();
        itemCustomer = new javax.swing.JMenuItem();
        mnuFeedBack = new javax.swing.JMenu();
        itemFeedBack = new javax.swing.JMenuItem();
        mnuHelp = new javax.swing.JMenu();
        itemAboutUs = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        desktop.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        desktop.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                desktopComponentResized(evt);
            }
        });
        getContentPane().add(desktop, java.awt.BorderLayout.CENTER);

        mnuFile.setText("File ");
        mnuFile.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        mnuFile.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnuFileMouseClicked(evt);
            }
        });
        mnuFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuFileActionPerformed(evt);
            }
        });

        itemLogin.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        itemLogin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Login.png"))); // NOI18N
        itemLogin.setMnemonic('L');
        itemLogin.setText("Login");
        itemLogin.setToolTipText("");
        itemLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemLoginActionPerformed(evt);
            }
        });
        mnuFile.add(itemLogin);

        itemLogout.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        itemLogout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/exit.png"))); // NOI18N
        itemLogout.setText("Logout");
        itemLogout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemLogoutActionPerformed(evt);
            }
        });
        mnuFile.add(itemLogout);

        itemExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        itemExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/exit_1.png"))); // NOI18N
        itemExit.setText("Exit");
        itemExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemExitActionPerformed(evt);
            }
        });
        mnuFile.add(itemExit);

        jMenuBar1.add(mnuFile);

        mnuMenu.setText("Menu ");
        mnuMenu.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N

        itemMenuInfo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
        itemMenuInfo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/mnuInfo.png"))); // NOI18N
        itemMenuInfo.setText("Menu information");
        itemMenuInfo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                itemMenuInfoMouseClicked(evt);
            }
        });
        itemMenuInfo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemMenuInfoActionPerformed(evt);
            }
        });
        mnuMenu.add(itemMenuInfo);

        jMenuBar1.add(mnuMenu);

        mnuBill.setText("Bill ");
        mnuBill.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        mnuBill.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnuBillMouseClicked(evt);
            }
        });

        itemBill.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        itemBill.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Bill.png"))); // NOI18N
        itemBill.setText("Managenment Bill");
        itemBill.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemBillActionPerformed(evt);
            }
        });
        mnuBill.add(itemBill);

        jMenuBar1.add(mnuBill);

        mnuStaffManagement.setText("Manager ");
        mnuStaffManagement.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        mnuStaffManagement.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnuStaffManagementMouseClicked(evt);
            }
        });

        itemManager.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        itemManager.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/group.png"))); // NOI18N
        itemManager.setText("Manager Information");
        itemManager.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemManagerActionPerformed(evt);
            }
        });
        mnuStaffManagement.add(itemManager);

        jMenuBar1.add(mnuStaffManagement);

        mnuAdminManagement.setText("Customer ");
        mnuAdminManagement.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        mnuAdminManagement.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnuAdminManagementMouseClicked(evt);
            }
        });

        itemCustomer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        itemCustomer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/group.png"))); // NOI18N
        itemCustomer.setText("Customer Information");
        itemCustomer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemCustomerActionPerformed(evt);
            }
        });
        mnuAdminManagement.add(itemCustomer);

        jMenuBar1.add(mnuAdminManagement);

        mnuFeedBack.setText("FeedBack ");
        mnuFeedBack.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        mnuFeedBack.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnuFeedBackMouseClicked(evt);
            }
        });
        mnuFeedBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuFeedBackActionPerformed(evt);
            }
        });

        itemFeedBack.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        itemFeedBack.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/foward.png"))); // NOI18N
        itemFeedBack.setText("Managenment FeedBack");
        itemFeedBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemFeedBackActionPerformed(evt);
            }
        });
        mnuFeedBack.add(itemFeedBack);

        jMenuBar1.add(mnuFeedBack);

        mnuHelp.setText("Help");
        mnuHelp.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N

        itemAboutUs.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        itemAboutUs.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/help.png"))); // NOI18N
        itemAboutUs.setText("About us");
        itemAboutUs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemAboutUsActionPerformed(evt);
            }
        });
        mnuHelp.add(itemAboutUs);

        jMenuBar1.add(mnuHelp);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void itemMenuInfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemMenuInfoActionPerformed

        desktop.removeAll();
        desktop.add(menu);
        menu.setVisible(true);

    }//GEN-LAST:event_itemMenuInfoActionPerformed

    private void mnuFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuFileActionPerformed
    }//GEN-LAST:event_mnuFileActionPerformed

    private void mnuFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnuFileMouseClicked
    }//GEN-LAST:event_mnuFileMouseClicked

    private void mnuStaffManagementMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnuStaffManagementMouseClicked
    }//GEN-LAST:event_mnuStaffManagementMouseClicked

    private void desktopComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_desktopComponentResized
        lblShowDes.setLocation((this.getSize().width - 780) / 2, 150);
        lblGroup.setLocation((this.getSize().width - 500) / 2, 240);
    }//GEN-LAST:event_desktopComponentResized

    private void itemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemExitActionPerformed
        try {
            if (JOptionPane.showConfirmDialog(this, "Do you want to exit?", "Notice", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                showInfo();
                CheckForm.closeFrame(this);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error: " + ex.getMessage(), "Notice", JOptionPane.OK_OPTION);
        }
    }//GEN-LAST:event_itemExitActionPerformed

    private void itemLogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemLogoutActionPerformed
        try {
            if (JOptionPane.showConfirmDialog(this, "Do you want to logout?", "Notice", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                showInfo();
                this.setEnabledItem(itemLogout, false);
                this.setEnabledItem(itemLogin, true);
                this.setEnabledItem(mnuAdminManagement, false);
                this.setEnabledItem(mnuStaffManagement, false);
                this.setEnabledItem(mnuBill, false);
                this.setEnabledItem(mnuFeedBack, false);
                this.setEnabledItem(mnuMenu, false);
                lblUserName.setVisible(false);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error: " + ex.getMessage(), "Notice", JOptionPane.OK_OPTION);
        }
    }//GEN-LAST:event_itemLogoutActionPerformed

    private void itemLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemLoginActionPerformed
        try {
            new GUILogin().setVisible(true);
           
            this.setVisible(false);
        } catch (Exception ex) {
            Logger.getLogger(FrAdmin.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_itemLoginActionPerformed

    private void itemMenuInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_itemMenuInfoMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_itemMenuInfoMouseClicked

    private void mnuFeedBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuFeedBackActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_mnuFeedBackActionPerformed

    private void mnuFeedBackMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnuFeedBackMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_mnuFeedBackMouseClicked

    private void mnuBillMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnuBillMouseClicked
    }//GEN-LAST:event_mnuBillMouseClicked

    private void mnuAdminManagementMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnuAdminManagementMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_mnuAdminManagementMouseClicked

    private void itemBillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemBillActionPerformed
        // TODO add your handling code here:
        desktop.removeAll();
        mb = new GUIManagerBill(manager);
        desktop.add(mb);
        mb.setVisible(true);
    }//GEN-LAST:event_itemBillActionPerformed

    private void itemManagerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemManagerActionPerformed
        // TODO add your handling code here:
        desktop.removeAll();
        desktop.add(mana);
        mana.setVisible(true);
    }//GEN-LAST:event_itemManagerActionPerformed

    private void itemCustomerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemCustomerActionPerformed
        // TODO add your handling code here:
        desktop.removeAll();
        desktop.add(maCus);
        maCus.setVisible(true);

    }//GEN-LAST:event_itemCustomerActionPerformed

    private void itemFeedBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemFeedBackActionPerformed
        // TODO add your handling code here:
        desktop.removeAll();
        desktop.add(fb);
        fb.setVisible(true);
    }//GEN-LAST:event_itemFeedBackActionPerformed

    private void itemAboutUsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemAboutUsActionPerformed
        // TODO add your handling code here:
        desktop.removeAll();
        au = new GUIAboutUs();
        desktop.add(au);
        au.setVisible(true);
    }//GEN-LAST:event_itemAboutUsActionPerformed
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /*
//         * If Nimbus (introduced in Java SE 6) is not available, stay with the
//         * default look and feel. For details see
//         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(FrAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(FrAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(FrAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(FrAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            @Override
//            public void run() {
//
//                new FrAdmin().setVisible(true);
//
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane desktop;
    private javax.swing.JMenuItem itemAboutUs;
    private javax.swing.JMenuItem itemBill;
    private javax.swing.JMenuItem itemCustomer;
    private javax.swing.JMenuItem itemExit;
    private javax.swing.JMenuItem itemFeedBack;
    private javax.swing.JMenuItem itemLogin;
    private javax.swing.JMenuItem itemLogout;
    private javax.swing.JMenuItem itemManager;
    private javax.swing.JMenuItem itemMenuInfo;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenu mnuAdminManagement;
    private javax.swing.JMenu mnuBill;
    private javax.swing.JMenu mnuFeedBack;
    private javax.swing.JMenu mnuFile;
    private javax.swing.JMenu mnuHelp;
    private javax.swing.JMenu mnuMenu;
    private javax.swing.JMenu mnuStaffManagement;
    // End of variables declaration//GEN-END:variables
    private JLabel lblGroup = new JLabel();
    private JLabel lblShowDes = new JLabel();
    private JLabel lblUserName = new JLabel();
}
